import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.0
import QtQuick.Controls.Styles 1.0



Item {

    property int editIndex


    TitleText {
        id: titleText
        text: "Edit Character Class"

        anchors.top: parent.top
        anchors.right: parent.right
        anchors.left: parent.left
        color: "white"
    }

    Column {
        anchors.top: titleText.bottom
        anchors.right: parent.right
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.topMargin: 12
        anchors.leftMargin: 9
        spacing: 9

        Column
        {
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: 3

            Text {
                color: "white"
                text: "Name"
                font.bold: true
                anchors.left: parent.left
                anchors.right: parent.right
            }

            Rectangle {
                color: "white"
                anchors.left: parent.left
                anchors.right: parent.right
                height: 20

                TextInput {
                    id: nameInput
                    text: characterModel.get(editIndex).name;
                    anchors.fill: parent
                    verticalAlignment: TextInput.AlignVCenter
                    anchors.margins: 3

                }
            }
        }

        Column
        {
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: 3

            Text {
                color: "white"
                text: "Acronym"
                font.bold: true
                anchors.left: parent.left
                anchors.right: parent.right
            }

            Rectangle {
                color: "white"
                anchors.left: parent.left
                anchors.right: parent.right
                height: 20

                TextInput {
                    id: acronymInput
                    text: characterModel.get(editIndex).acronym;
                    anchors.fill: parent
                    verticalAlignment: TextInput.AlignVCenter
                    anchors.margins: 3

                }
            }
        }

        Column
        {
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: 3

            Text {
                color: "white"
                text: "Hit Die"
                font.bold: true
                anchors.left: parent.left
                anchors.right: parent.right
            }

            ComboBox {
                id: hitDieCombo

                model: hitDiceList
                textRole: "name"
                currentIndex: characterModel.get(editIndex).hitDieIndex
                anchors.left: parent.left
                anchors.right: parent.right
            }

        }

        Column
        {
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: 3

            Text {
                color: "white"
                text: "Skill Points"
                font.bold: true
                anchors.left: parent.left
                anchors.right: parent.right
            }

            ComboBox {
                id: skillPointCombo

                model: skillPointsList
                textRole: "name"
                currentIndex: characterModel.get(editIndex).skillPointIndex
                anchors.left: parent.left
                anchors.right: parent.right
            }
        }

        Column
        {
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: 3

            Text {
                color: "white"
                text: "Class Skills"
                font.bold: true
                anchors.left: parent.left
                anchors.right: parent.right
            }

            Repeater {
                id: classSkillRepeater
                model: skillsModel
                delegate: CheckBox {
                    anchors.left: parent.left
                    anchors.right: parent.right

                    /// \todo Fix bug here, for some reason Computer Use and some other skills
                    ///         are always checked as class skills...
                    checked: {characterModel.get(editIndex).skills.search(name) >= 0 }

                    style: CheckBoxStyle {
                        label: Label {
                            color: "white"
                            text: name
                        }
                    }
                }
            }
        }

        Column
        {
            anchors.left: parent.left
            anchors.right: parent.right
            spacing: 3

            Button {
                text: "Apply"
                anchors.right: parent.right

                onClicked: {
                    editIndex.name = nameInput.text;
                    editIndex.acronym = acronymInput.text;
                    editIndex.hitDieIndex = hitDieCombo.currentIndex;
                    editIndex.skillPointIndex = skillPointCombo.currentIndex;
                    /// \todo: Class skills?
                }
            }
        }
    }
}


